package org.free.learn.base64;

import org.base64.Base64;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import java.io.*;

/**
 * User: MiaoK
 * Date: 11-8-25
 * Time: 下午3:32
 */
public class Base64Encoder {
    /**
     * 载入png图片，并编码为base64格式
     */
    public void imageStreamBase64(){
        try {
//            byte[] ret = null;
//            FileInputStream in = new FileInputStream("D:/Work/code/learn-free/run/michael_zxing.png");
//            ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
//            byte[] b = new byte[4096];
//            int n;
//            while ((n = in.read(b)) != -1) {
//                out.write(b, 0, n);
//            }
//            in.close();
//            out.close();
//            ret = out.toByteArray();

            String img64 = Base64.encodeFromFile("D:/Work/code/learn-free/run/michael_zxing.png");
            System.out.print(img64);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        Base64Encoder isb64 = new Base64Encoder();
        isb64.imageStreamBase64();
    }
}
